package com.lagou.service.impl;

import com.lagou.dao.IArticleRepository;
import com.lagou.pojo.Article;
import com.lagou.service.IArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ArticleServiceImpl implements IArticleService {

    @Autowired
    private IArticleRepository articleRepository;

    @Override
    public List<Article> findAll() {
        return articleRepository.findAll();
    }

    @Override
    public Page<Article> pageQuery(Integer pageNum, Integer pageSize) {
        pageNum = pageNum == null || pageNum == 0 ? 0 : pageNum;
        pageSize = pageSize == null || pageSize == 0 ? 2 : pageSize;
        PageRequest request = PageRequest.of(pageNum, pageSize);
        return articleRepository.findAll(request);
    }
}
